Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

284
Visualizações
formatCreateLabel does not display "Create new label..." for some cases react-slect/creatable

I am using react-select/creatable library to display dropdowns with options. I wanted to make use of the formatCreateLabel prop which displays a label. This label is based on the topmost option in the dropdown, so essentially in the formatCreateLabel function, I am sorting my list which is dynamic, and based on the topmost option I am showing the create option. Few things to note here - the create option is dependent on the topmost option in the dropdown list. I also wanted to show the create option even if there is an exact match.

Snippet of the format function -

const formatCreateLabel = (input) => {
        
        const options = getSortedList(input, list); // using sort-matcher library for sorting
    
        const firstItem = _.first(options);
        const label = _.get(firstItem, 'label');

        if (!_.isNil(firstItem))
            return `Create wildcard "${label}"`;
    };

/** My list option looks something like this (eg.)
    const listOptions = [
         { label: 'alpha', key: 'a', value: 'a' },
         { label: 'alpea', key: 'ae', value: 'ae' },
         { label: 'beta', key: 'b', value: 'b' },
         { label: 'user.name', key: 'user.name', value: 'user.name' },
         { label: 'name', key: 'name', value: 'name' },
    ];
**/


   <CreatableSelect
      key={key}
      options={list}
      value={value}
      onChange={onChange}
      placeholder="Select..."
      formatCreateLabel={formatCreateLabel}
      {...props}
  />

The issue is the label is sometimes shown sometimes it is not although I can see that a valid value is being returned from the formatCreateLabel function. What could be the issue here? Also is there a way to continue showing the create new option even if there is an exact match?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda